import React from "react";
import { Menu, Dropdown, Icon, Affix } from 'antd';
import Link  from "umi/link";
import router from 'umi/router';
import withRouter from 'umi/withRouter';

const MenuItem = Menu.Item;
const index=({location})=>{
    // console.log(location)
    const onLogout = () => {
      localStorage.clear();
      router.push('/login');
    };
    const menu=(
        <Menu>
            <MenuItem>
          <span onClick={onLogout}>退出</span>
            </MenuItem>
        </Menu>
    );
    return (
      <Affix offsetTop={0}>
        <div className="header">
          <img className="logo" src={require('@/assets/gogo.gif')} alt="logo" />
          {/* <img className="logo" src={require('@/assets/logo2.png')} alt="logo" /> */}
          <Menu className="menus" mode="horizontal" theme="dark" selectedKeys={[location.pathname]}>
            <MenuItem key="/">
              <Link to="/">首页</Link>
            </MenuItem>
            <MenuItem key="/users">
              <Link to="/users">用户</Link>
            </MenuItem>
            <MenuItem key="/reports">
              <Link to="/reports">周报</Link>
            </MenuItem>
          </Menu>
          <div className="right">
            <Dropdown overlay={menu}>
              <a className="ant-dropdown-link" href={location.pathname}>
                <Icon type="user" style={{ marginRight: 3 }}></Icon>{localStorage.getItem('nickname')}
              </a>
            </Dropdown>
          </div>
        </div>
      </Affix>
    );
};
export default withRouter(index);